<{include file="Order_v2/top.html" }>
</head>
<body>
<div id="wrap" class="pt buy-page">
    <div class="header">
        支付信息
        <a href="javascript:window.history.back();" class="back"></a>
    </div>

    <div class="section-1">
        <div class="thumb" style="background: url(<{$preuploadcurl}><{$data.imgList}>) no-repeat;"></div>
        <div class="list">
            <p>商品名称: <{$orderInfo.orderTitle}></p>

            <{if $data.showListTime}>
                <p class="red">活动时间：<{$data.showListTime}></p>
            <{else}>
                <p>类型：<{$data.deliveryType}></p>
            <{/if}>

            <p class="gray">市场参考价: <{$orderInfo.marketPrice}>元</p>
        </div>
    </div>

    <div class="section-2">
        <{if $orderInfo.userName}>
        <div class="ui-item">
            <span class="ui-label">用户姓名:</span>
            <span class="flex red"><{$orderInfo.userName}></span>
        </div>
        <{/if}>
        <{if $orderInfo.phone}>
        <div class="ui-item">
            <span class="ui-label">联系电话:</span>
            <span class="flex red"><{$orderInfo.phone}></span>
        </div>
        <{/if}>
        <{if $orderInfo.address}>
        <div class="ui-item">
            <span class="ui-label">用户地址:</span>
            <span class="flex red"><{$orderInfo.address}></span>
        </div>
        <{/if}>
    </div>
    <div class="section-2">
        <div class="ui-item">
            <span class="ui-label">支付金额:</span>
            <span class="flex red">人民币<{$orderInfo.pay}>元</span>
        </div>
        <div class="ui-item">
            <span class="ui-label">付款方式:</span>
            <div class="ui-filed flex clearfix">
                <label>微信支付</label>
                <span class="red"><{$orderInfo.pay}>元</span>
            </div>
        </div>
    </div>

    <div class="btn-group">
        <a href="javascript:void(0);" class="pay" id="payment">确认支付</a>
    </div>
</div>




<script type="text/javascript">
    var balance = toDecimal('<{$userInfo.money}>');
    var pay = toDecimal('<{$orderInfo.pay}>');
    var pay_money = pay;
    var pay_balance = 0;
    var apiMsg = {};


    $(function () {
        var loadObj;
        var btnFlag = 1;
        $("#payment").on('click', function () {
            if(!pay_money && !pay_balance){
                return false;
            }
            loadObj = load();
            if(!btnFlag) return false;
            btnFlag = 0;
            $.getJSON("<{U('Order/getPay')}>", {id:'<{$orderInfo.id}>', uid:'<{$orderInfo.uid}>', pay_money:pay_money, pay_balance:pay_balance}, function(data){
                layer.close(loadObj);
                btnFlag = 1;
                if(data.status!=0){
                    if(data.status == 3){
                        window.location.href = data.url;
                        return false;
                    }
                    tip(data.msg);
                    if(data.status == 2){
                        window.history.go(-1);
                        return false;
                    }
                }else{
                    if(pay_balance>0 && pay_money == 0){
                        checkOrder();
                    }else{
                        apiMsg = JSON.parse(data.data);
                        callpay();
                    }
                }
            });
        });
    });

    //重新
    function checkOrder() {
        loadObj = load();
        $.getJSON("<{U('Order/checkOrderStatus')}>", {id:'<{$orderInfo.id}>', uid:'<{$orderInfo.uid}>'}, function(data){
            layer.close(loadObj);
            if(data.status!=0){
                tip(data.msg);
            }else{
                window.location.href = data.url;
            }
        });
    }


    function callpay()
    {
        if(!canpay){
            return false;
        }
        var data={
            "success":function(){checkOrder();},
            "fail":function(res){
                tip("支付失败，请重试或联系客服");
            },
            'timestamp':apiMsg.timeStamp,
            'nonceStr':apiMsg.nonceStr,
            'package':apiMsg.package,
            'signType':apiMsg.signType,
            'paySign':apiMsg.paySign

        }
        wx.chooseWXPay(data);

        return true;

    }
</script>
</body>
</html>

